
package com.woniu.main.goods.handler;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.woniu.main.goods.pojo.GoodsUnreviewed;
import com.woniu.main.goods.service.GoodsAuditedService;
import com.woniu.main.goods.service.GoodsAutoAuditService;
import com.woniu.main.goods.service.GoodsUnreviewedService;

@RestController
@RequestMapping("/Unreviewed")
public class GoodsUnreviewedController {
	@Autowired
	private GoodsUnreviewedService goodsUnreviewedService;
	@Autowired
	private GoodsAutoAuditService goodsAutoAuditService;
	@Autowired
	private GoodsAuditedService goodsAuditedService;

	/*
	 * 
	 * 查询所有，申诉的，未通过审核的物品
	 */
	@RequestMapping("/appeal")
	public List<GoodsUnreviewed> findAllUnreviewed() {
		return goodsUnreviewedService.findfindAllUnreviewed();

	}

	/*
	 * 
	 * 提交的物品进行自动审核
	 */
	@RequestMapping("/audit")
	public String autoAudit(GoodsUnreviewed goodsUnreviewed) throws FileNotFoundException, IOException {
		String result = "审核通过";
		/* goodsUnreviewed.getGoods_name() */
		if (goodsAutoAuditService.autoAuditName(goodsUnreviewed.getGoods_name()) == false) {
			System.out.println("商品命名违反社会主义核心价值观");
			return result = "商品命名违反社会主义核心价值观";
		}

		/* goodsUnreviewed.getGoods_desc() */
		if (goodsAutoAuditService.autoAuditTest(goodsUnreviewed.getGoods_desc()) == false) {
			System.out.println("商品描述违反社会主义核心价值观");
			return result = "商品描述违反社会主义核心价值观";
		}

		/* goodsUnreviewed.getGoods_pic() */
		if (goodsAutoAuditService.autoAuditPicture(goodsUnreviewed.getGoods_pic()) == false) {
			System.out.println("商品图片违反社会主义核心价值观");
			return result = "商品图片违反社会主义核心价值观";
		}
		if (result.equals("审核通过")) {
			goodsAuditedService.insertAudited(goodsUnreviewed);
		}
		return result;

	}

}
